<?php
/**
 * Created by PhpStorm.
 * Time: 下午5:02
 */


namespace swf\syncdb;

use swf\core\Config;

class Redis{
    private static $instance = null;
    private static $redis;
    private function __construct($config = null){
        $redis = new \Redis();
        if(is_null($config))
        {
            $config = Config::get('redis');
        }
        $redis->connect($config['ip'],$config['port']);
        $redis->auth($config['password']);
        $redis->select($config['select']);
        if($redis->ping() != '+PONG')
        {
            throw new \Exception('server is not connect!');
        }
        self::$redis = $redis;

    }

    public static function getDb($config = null)
    {
        if(empty($instance))
        {
            self::$instance = new self($config);
        }
        return self::$redis;
    }

}